package cn.wen.yaling.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wen.yaling.aop.annotation.operation.OperationLogger;
import cn.wen.yaling.commons.vo.TodoAddVO;
import cn.wen.yaling.commons.vo.TodoAdminListVO;
import cn.wen.yaling.commons.vo.TodoUpdateVO;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import cn.wen.yaling.commons.entity.TodoEntity;
import cn.wen.yaling.xo.service.TodoService;
import cn.wen.yaling.commons.utils.PageUtils;
import cn.wen.yaling.commons.utils.ResultEntity;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author FY
 * @email 932043654@qq.com
 * @date 2022-08-13 02:07:37
 */
@RestController
public class TodoController {

    @Autowired
    private TodoService todoService;

    @ApiOperation(value = "获取代办事项列表", notes = "获取代办事项列表", response = ResultEntity.class)
    @GetMapping("/admin/todo/list")
    public ResultEntity getTodoList() {
        List<TodoAdminListVO> list = todoService.getTodoListByDone(false);
        if (list.size() > 0) return ResultEntity.ok().put("data", list);
        return ResultEntity.error();
    }

    @OperationLogger(value = "删除代办事项")
    @ApiOperation(value = "删除代办事项", notes = "删除代办事项", response = ResultEntity.class)
    @PostMapping("/admin/todo/delete")
    public ResultEntity delete(@RequestParam Integer[] todoIds){
		todoService.removeByIds(Arrays.asList(todoIds));

        return ResultEntity.ok();
    }

    @OperationLogger(value = "增加代办事项")
    @ApiOperation(value = "增加代办事项", notes = "增加代办事项", response = ResultEntity.class)
    @PostMapping("/admin/todo/add")
    public ResultEntity add(@RequestBody TodoAddVO todoVO) {
        return todoService.addTodo(todoVO);
    }

    @OperationLogger(value = "已做代办事项")
    @ApiOperation(value = "已做代办事项", notes = "已做代办事项", response = ResultEntity.class)
    @PostMapping("/admin/todo/active")
    public ResultEntity active(@RequestParam List<Integer> todoList) {
        return todoService.activeTodo(todoList);
    }


    @OperationLogger(value = "编辑代办事项")
    @ApiOperation(value = "编辑代办事项", notes = "编辑代办事项", response = ResultEntity.class)
    @PostMapping("/admin/todo/update")
    public ResultEntity edit(@RequestBody TodoUpdateVO todoVO) {
        return todoService.updateTodo(todoVO);
    }

}
